﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Practices.Prism.ViewModel;
using System.IO;

namespace wpf_ImageSearch.Model
{
    public class Settings : NotificationObject
    {
        public static readonly string SettingsFile = @".\settings.xml";

        public static Settings Load()
        {
            try
            {
                using (var reader = new StreamReader(SettingsFile))
                {
                    return new XmlSerializer(typeof(Settings)).Deserialize(reader) as Settings;
                }
            }
            catch
            {
                return new Settings();
            }
        }

        public void Save()
        {
            using (var writer = new StreamWriter(SettingsFile))
            {
                new XmlSerializer(typeof(Settings)).Serialize(writer, this);
            }
        }

        private double left = double.NaN;
        public double Left
        {
            set
            {
                left = value;
                RaisePropertyChanged(() => Left);
            }
            get
            {
                return left;
            }
        }

        private double top = double.NaN;
        public double Top
        {
            set
            {
                top = value;
                RaisePropertyChanged(() => Top);
            }
            get
            {
                return top;
            }
        }

        private double width = 525d;
        public double Width
        {
            set
            {
                width = value;
                RaisePropertyChanged(() => Width);
            }
            get
            {
                return width;
            }
        }

        private double height = 350d;
        public double Height
        {
            set
            {
                height = value;
                RaisePropertyChanged(() => Height);
            }
            get
            {
                return height;
            }
        }

        private double thumbnailSize = 170d;
        public double ThumbnailSize
        {
            set
            {
                thumbnailSize = value;
                RaisePropertyChanged(() => ThumbnailSize);
            }
            get
            {
                return thumbnailSize;
            }
        }
    }
}
